<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>数据提交</title>
</head>
<body>
<input type="hidden" id="basePath" value="${request.Con}">
<table>
    <tr>
        <td>key</td>
        <td><input type="text" name="key" id="key"></td>
    </tr>
    <tr>
        <td>value</td>
        <td><input type="text" name="value" id="value"></td>
    </tr>
    <tr>
        <td>time</td>
        <td><input type="number" max="1000" min="0" name="time" id="time"></td>
    </tr>
    <tr><td colspan="2">
        <button id="redis_set_string" >增加key和数据</button>
        <button id="redis_get_string" >获取key中数据</button>
        <button id="redis_set_string_time" >增加带有时间限制的key</button>
        <button id="redis_get_string_time" >获取带有时间限制的key</button>
    </td></tr>
</table>

</body>
<script crossorigin="anonymous" integrity="sha384-AQhQSZGQWTMJhb/TdS7NWpCmOM/8lIEsaevSU5oZtt8pQKoa+uJL4A2WnQ0O5Zj2" src="https://lib.baomitu.com/jquery/3.5.0/jquery.js"></script>
<script type="text/javascript">
    let path = window.location.href;
    let basePath = window.location.origin+"/"+path.split("/")[3];
    let Controller={
        bind:function(){
            console.log("load bind");
            $("button").bind("click",function(){
                debugger;
                let _this = $(this);
                let id =  _this.attr("id");
                let ids = id.split("_");
                let _c = Controller;

                let key = $("#key").val();
                let value = $("#value").val();
                let time = $("#time").val();

                let url = basePath;
                for (let temp in ids){
                    url += "/" + ids[temp];
                }
                let type = "get";
                if(ids[1]=="set"){
                    type="put";
                    url += "/" +key + "_" +value;
                    if(ids.length == 4){
                        url += "_" + ids[3];
                    }
                }else{
                    url = url + "/" +key
                }
                console.log(basePath);

                _c.ajax(url,type,{});
            });
        },
        ajax:function(url,type,data){
            let datas={
                type:type,
                url:url,
                data:data,
                dataType:"json",
                success:function(result){
                    alert(result);
                }
            }
            $.ajax(datas);
        }
    };
    $(document).ready(function(){
        let  _c = Controller;
        _c.bind();
    });
</script>
</html>